//
//  HMBaseNavController.swift
//  sina
//
//  Created by 崔正强 on 17/3/19.
//  Copyright © 2017年 崔正强. All rights reserved.
//

import UIKit  

class HMBaseNavController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.interactivePopGestureRecognizer?.delegate = self
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //调用设置根视图控制器的构造方法 在该方法内部会执行push压栈的操作
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        let count = viewControllers.count
        if count > 0 {
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "返回", imageName:"navigationbar_back_withtext" , target: self, action: #selector(back))
            viewController.view.backgroundColor = UIColor.white
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: animated)
    }

    @objc private func back() {
        let _ = self.popViewController(animated: true)
        
    }
    
    //实现手势的协议方法
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        //根据条件 让手势能否工作
        //判断是否是根视图控制器
        let count = childViewControllers.count
        
        return count > 1
        
    }
    
}
